<?php

function existeChamp($database_microassur, $microassur, $table, $champ, $valeurChamp){

	$query_rs = "SELECT COUNT(*) as nombre FROM $table WHERE $champ = '$valeurChamp'";
	$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	mysql_free_result($rs);
	return $row_rs['nombre'];
}
function existeChamp1($database_microassur, $microassur, $table, $champ,$id,$valeurChamp){
	$identifiant="Identifiant_".$table;
	$query_rs = "SELECT COUNT(*) as nombre FROM $table WHERE $champ = '$valeurChamp' and $identifiant!=$id";
	$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	mysql_free_result($rs);
	return $row_rs['nombre'];
}
function existeChamp2($database_microassur, $microassur, $table, $champ,$id,$valeurChamp){
	$identifiant="Identifiant_condition_indemnisation";
	$query_rs = "SELECT COUNT(*) as nombre FROM $table WHERE $champ = '$valeurChamp' and $identifiant!=$id";
	$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	mysql_free_result($rs);
	return $row_rs['nombre'];
}
function verifLibelle($val)
	{
		if(isset($_POST["$val"])&& ($_POST["$val"]!=NULL))
			return TRUE;
		else 
			return FALSE;
	}
function dateEN2FR($date)
	{
		if(isset($date))
		{
			$date = str_replace('/','-',$date);
			$date = explode('-', $date);
			$dateFr = $date[2].'-'.$date[1].'-'.$date[0];
			return $dateFr;
		}
	}
function verifDate($date1,$date2)
	{
		if(isset($date1) && isset($date2))
		{
			if($date1!="" && $date2!="")
			{
				$date1 = str_replace('/','-',$date1);
				$date2 = str_replace('/','-',$date2);
				$date1 = explode('-', str_replace(' ','',$date1));
				$date2 = explode('-', str_replace(' ','',$date2));
				if (is_numeric($date1[0]) && is_numeric($date2[0]))
				{
					if(($date2[2]>=$date1[2] ) && (is_numeric($date1[2]) && is_numeric($date2[2])))
					{
						if(($date2[1]>=$date1[1]) && (is_numeric($date1[1]) && is_numeric($date2[1])) && ($date2[1]<=intval(12)) && ($date1[1]<=intval(12)))
						{
							if($date1[1]==intval(2))
							{
								if(($date2[0]<=intval(31)) && ($date1[0]<=intval(29)))
									return true;
								else
									return false;
							}
							elseif($date2[1]==intval(2))
							{
								if(($date2[0]<=intval(29)) && ($date1[0]<=intval(31)))
									return true;
								else
									return false;
							}
							elseif($date1[1]==intval(4)||$date1[1]==intval(6)||$date1[1]==intval(9)||$date1[1]==intval(11))
							{
								if(($date2[0]<=intval(31)) && ($date1[0]<=intval(30)))
									return true;
								else
									return false;
							}
							elseif($date2[1]==intval(4)||$date2[1]==intval(6)||$date2[1]==intval(9)||$date2[1]==intval(11))
							{
								if(($date1[0]<=intval(31)) && ($date2[0]<=intval(30)))
									return true;
								else
									return false;
							}
							elseif(($date2[1]==$date1[1]) && ($date2[1]==intval(1)||$date2[1]==intval(3)||$date2[1]==intval(5)||$date2[1]==intval(7)||$date2[1]==intval(8)||$date2[1]==intval(10)||$date2[1]==intval(12)) )
							{
								if (($date2[0]<=intval(31) && $date1[0]<=intval(31)) && ($date2[0]>$date1[0]))
									return true;
								else
									return false;
							}
							elseif(($date1[1]==$date1[1]) && ($date1[1]==intval(1)||$date1[1]==intval(3)||$date1[1]==intval(5)||$date1[1]==intval(7)||$date1[1]==intval(8)||$date1[1]==intval(10)||$date1[1]==intval(12)) )
							{
								if (($date2[0]<=intval(31) && $date1[0]<=intval(31)) && ($date2[0]>$date1[0]))
									return true;
								else
									return false;
							}
							else
								return false;
						}
						else
							return false;
					}
					else
						return false;
				}
				else
					return false;
			}
			else
				return false;
		}
		else
			return false;
	}
?>
